package ge.telasi.tasks.ui.reporting;

import ge.telasi.tasks.ejb.TaskFacadeRemote;
import ge.telasi.tasks.ui.Platform;
import ge.telasi.tasks.ui.comp.SimpleTable;
import ge.telasi.tasks.ui.comp.TableModel;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.swing.JTable;

/**
 * @author dimitri
 */
public class TaskCompleteTable extends SimpleTable<Map> {
    private Calendar startDate, endDate;

    public TaskCompleteTable() {
        setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    }

    public Calendar getEndDate() {
        return endDate;
    }

    public void setEndDate(Calendar endDate) {
        this.endDate = endDate;
    }

    public Calendar getStartDate() {
        return startDate;
    }

    public void setStartDate(Calendar startDate) {
        this.startDate = startDate;
    }

    @Override
    protected TableModel<Map> createEmptyModel() {
        return new MyTableModel();
    }

    @Override
    protected List<Map> getDataFromServer(Platform pl) throws Exception {
        TaskFacadeRemote facade = pl.getFacade();
        return facade.getTaskCompetedReportData(pl.getCredentials(), getStartDate(), getEndDate());
    }

    @Override
    protected String getPreferenceName() {
        return "TaskCompletedReport001";
    }

    @Override
    protected int[] getDefaultColumnWidthes() {
        return new int[] { 100, 200, 100, 100, 100, 100 };
    }

    class MyTableModel extends TableModel<Map> {
        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

        @Override
        public String getColumnName(int column) {
            switch(column) {
                case 0:
                    return "მომხმარებელი";
                case 1:
                    return "სახელი, გვარი";
                case 2:
                    return "ღია";
                case 3:
                    return "შესრულებული";
                case 4:
                    return "დახურული";
                case 5:
                    return "ყველა";
                default:
                    return "?";
            }
        }

        @Override
        public Class<?> getColumnClass(int column) {
            switch(column) {
                case 0:
                case 1:
                    return String.class;
                case 2:
                case 3:
                case 4:
                case 5:
                    return Integer.class;
                default:
                    return Object.class;
            }
        }

        @Override
        public Object getValueAt(int row, int column) {
            Map rowData = (Map) data.get(row);
            switch(column) {
                case 0:
                    return rowData.get("username");
                case 1:
                    return rowData.get("fullname");
                case 2:
                    return rowData.get("open");
                case 3:
                    return rowData.get("complete");
                case 4:
                    return rowData.get("closed");
                case 5:
                    return rowData.get("all");
                default:
                    return "?";
            }
        }
    }
}
